<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
    <script>var jsCtx = "${ctx}"</script>
<!-- 引入easyui样式 -->
<link rel="stylesheet" type="text/css" href="<%=basePath%>/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>/easyui/themes/icon.css" />
<link rel="stylesheet" type="text/css" href="<%=basePath%>/easyui/demo/demo.css" />
<script type="text/javascript" src="<%=basePath%>/backstage/js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="<%=basePath%>/easyui/jquery.easyui.min.js"></script>
<!-- 引入kineditor -->
<link href="<%=basePath%>/backstage/css/user.css" rel="stylesheet" />
<link href="<%=basePath%>/backstage/css/default.css" rel="stylesheet" />
<script type="text/javascript" src="<%=basePath%>/kindeditor/kindeditor-min.js"></script>
<script type="text/javascript" src="<%=basePath%>/kindeditor/lang/zh_CN.js"></script>
<script type="text/javascript" src="<%=basePath%>/resources/js/ajaxfileupload.js"></script>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="UTF-8">
	<title>DataGrid with Toolbar - jQuery EasyUI Demo</title>
</head>
<script type="text/javascript">
$(document).ready(function(){
 $("#add_user").window('close');
});
</script>


<script type="text/javascript">
function addaaa(){
     var id=$("#id").val();
$.ajaxFileUpload({
                url: jsCtx + '/scholarback/updatescholarimg?id='+id, //参数
				type: "post",
				secureuri: false, //一般设置为false
				fileElementId:'headimg1', //文件上传空间的id属性  
				//data: {questionBankId:questionBankId},
				dataType: 'json', //返回值类型 一般设置为json
				success: function (data, status) {
				  if(data.state==0){
				   alert("修改成功");
				   //刷新页面
					window.location.reload();
				  }else{
		            alert("修改失败");
		             }
				},
				error: function () {
				 alert("网络错误");
				}
			});
}
</script>

<body>

<table id="dg"></table>
   	<div id="add_user" class="easyui-window" title="修改学者头像" style="width:1200px; height:500px;">
	    <div style="margin: 10px 0;"></div>
	    <div style="padding: 10px 0 10px 60px">
        <form id="add" method="post">
            <table>
            <tr><td> <input class="easyui-validatebox" type="hidden" id="id" name="id"></input></td></tr>
               <tr>
                      <td>学者头像:</td>
                      <td>
                      <input class="easyui-validatebox" type="file" id="headimg1" name="headimg1"></input></td>
                </tr>
                <tr>
                 <td></td>
                    <td>
                    <!--  onclick="alert(editor.html())" -->
                        <input type="button" name="btn1" value="提交" onclick="addaaa()"/>
                    </td>
                </tr>
       
            </table>
        </form>
    </div>
   </div>
<script type="text/javascript">
    $(function(){
    //alert("<%=request.getContextPath()%>");
        $('#dg').datagrid({   
         width:1200, 
         height:'auto', 
           url:'<%=request.getContextPath()%>/scholarback/scholarList', 
            singleSelect:true,//是否单选 
            columns:[[    
                {field:'id',title:'学者编号',width:0,align:'center' },    
                {field:'name',title:'学者姓名',width:40,align:'center'},  
                {field:'position',title:'学者职位',width:0,align:'left'},   
                 {field:'headimg',title:'学者头像',width:200,align:'center'},
                {field:'description',title:'学者简介',width:0,align:'left',resizable:true}
            ]],
      toolbar: [ { 
            text: '修改头像', 
            iconCls: 'icon-edit', 
            handler: function() { 
                //openDialog("add_dialog","edit"); 
                  // var a=${news.title};
               var rows= $('#dg').datagrid('getSelections'); 
              // data=rows[0].title;
               //把增加新闻修改为修改新闻
               $("#id").val(rows[0].id);
             // editor.html(rows[0].description);
               $('#add_user').window({
          }); 
            } 
        }], 
            fitColumns:true,
            striped:true,
            pagination:true,
            rownumbers:true,
            pageNumber:1,
        }); 
    //设置分页控件 
     $('#dg').datagrid('hideColumn','position');
     $('#dg').datagrid('hideColumn','description');
     $('#dg').datagrid('hideColumn','id');
    var p = $('#dg').datagrid('getPager'); 
    $(p).pagination({ 
        pageSize: 3,//每页显示的记录条数，默认为10 
        pageList: [2,3,5,10,15,20],//可以设置每页记录条数的列表 
        beforePageText: '第',//页数文本框前显示的汉字 
        afterPageText: '页    共 {pages} 页', 
        displayMsg: '当前显示 第{from} - {to} 条记录   共 {total} 条记录', 
        /*onBeforeRefresh:function(){
            $(this).pagination('loading');
            alert('before refresh');
            $(this).pagination('loaded');
        }*/ 
    }); 
       })
</script>
   
</body>
</html>
